<template>
	<view class="confirmTransfer">
		<view class="transfer_account">转账账户 {{ account }}</view>
		<view class="transfer_money">转账币种 {{ccy == 0 ? '火源' : ccy == 1 ? '原力' : '火石'}}</view>
		<view class="transfer_money">转账金额</view>
		<fx-amountInput confirmText="转账" placeholder="请输入转账金额" @change="valChange" @confirm="confirm"></fx-amountInput>
	</view>
</template>

<script>
	import {
		toTransfer
	} from '@/config/api.js';
	export default {
		data() {
			return {
				account: '',  // 收款客户编号
				money: '',
				customerNo:'' ,// 转账客户编号
				ccy: 0, // 转账币种
			}
		},
		onLoad: function(option) {
			console.log('option', option)
			const {
				account, ccy
			} = option
			this.account = account
			this.ccy = Number(ccy)
		},
		// 监听页面显示,页面每次出现在屏幕上都触发
		onShow() {
			this.customerNo = uni.getStorageSync('customerNo')
		},
		methods: {
			// 金额发生改变
			valChange(val) {
				this.money = String(val)
			},
			// 确认转账
			confirm() {
				let data = {
					from : this.customerNo,
					to: this.account,
					ccy: this.ccy,
					amount: this.money
				}
				toTransfer({...data}).then(res => {
					// console.log(res)
					if(res){
						uni.showToast({
							icon: 'success',
							position: 'bottom',
							title: '转账交易成功'
						});
						setTimeout(()=>{
							uni.navigateTo({
								url: `/pages/sucess/sucess?customerNo=${this.customerNo}&money=${this.money}`
							});
						},2000)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.confirmTransfer {
		padding: 40rpx;

		.transfer_money,
		.transfer_account {
			font-size: 32rpx;
			padding-bottom: 40rpx;
		}
	}
</style>
